package inet.app.vod.adapter;

import inet.app.vod.activity.R;
import inet.app.vod.object.MovieModel;

import java.util.List;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.inet.app.framework.bitmap.UniversalImageUtil;

public class FilmSuggestAdapter extends ArrayAdapter<MovieModel> {

	private List<MovieModel> mMovieModels;
	private Activity mContext;
	private LayoutInflater mInflater;

	public FilmSuggestAdapter(Activity context, int textViewResourceId,
			List<MovieModel> objects) {

		super(context, textViewResourceId, objects);
		this.mContext = context;
		this.mInflater = this.mContext.getLayoutInflater();
		this.mMovieModels = objects;
	}

	@Override
	public int getCount() {
		return mMovieModels.size();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder = null;
		final MovieModel model = mMovieModels.get(position);

		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.item_listview_suggestfilm,
					null);

			holder = new ViewHolder();
			holder.mThumb = (ImageView) convertView
					.findViewById(R.id.film_thumb);
			holder.mNameFilmVietnamese = (TextView) convertView
					.findViewById(R.id.name_film_vietnamese);
			holder.mNumView = (TextView) convertView
					.findViewById(R.id.num_view_text);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		UniversalImageUtil.getInstance(mContext).displayImage(model.getImg(),
				holder.mThumb);
		holder.mNameFilmVietnamese.setText(model.getTitle());
		holder.mNumView.setText(String.valueOf(model.getNumView()));

		return convertView;
	}

	static class ViewHolder {
		public ImageView mThumb;
		public TextView mNameFilmVietnamese;
		public TextView mNumView;
	}
}
